#define _CRT_SECURE_NO_WARNINGS 1

#include "SList.h"

Listnode* partition(Listnode* head, Listdatatype x) {
    Listnode* listlit, * listbig;
    Listnode* litpcur, * bigpcur;
    listlit = listbig = litpcur = bigpcur = NULL;
    Listnode* pcur = head;

    if (pcur == NULL)
    {
        return NULL;
    }
    while (pcur != NULL)
    {
        if (pcur->data < x)
        {
            if (listlit == NULL)
            {
                listlit = litpcur = pcur;
            }
            else {
                litpcur->next = pcur;
                if (pcur)
                {
                    litpcur = pcur;
                }
            }
        }
        else
        {
            if (listbig == NULL)
            {
                listbig = bigpcur = pcur;
            }
            else
            {
                bigpcur->next = pcur;
                bigpcur = pcur;
            }
        }
        pcur = pcur->next;
    }
    if (litpcur)
        litpcur->next = listbig;
    else
        return head;
    if(bigpcur)
        bigpcur->next = NULL;

    return listlit;
}
int main()
{
    Listnode* phead = NULL;
    Listpushback(&phead, 1);
    Listpushback(&phead, 4);
    Listpushback(&phead, 3);
    Listpushback(&phead, 2);
    Listpushback(&phead, 5);
    Listpushback(&phead, 2);
    Listnode* list = partition(phead, 3);
    Listprint(list);
	return 0;
}